local root "N:\Project\50732_RDRC\DC1\~51702\BC23-TBD (SSI Medicaid)\Data\Output\"

local yr 2019
local dt 20230703

// Looping over assorted variables included here -- paper only includes number of RX claims (39) and developmental delays (27)
foreach obsnum in  2 8 10 18 20 26 27 38 39 {
	
if `obsnum' == 2 {
	local var adhd
	local ylim 0(10)60
	local mult 100
}
if `obsnum' == 8 {
	local var speech
	local ylim 0(10)70
	local mult 100
}
if `obsnum' == 10 {
	local var lea
	local ylim 0(10)60
	local mult 100
}
if `obsnum' == 18 {
	local var tos_phys
	local ylim 0(20)100
	local mult 100
}
if `obsnum' == 20 {
	local var tos_rx
	local ylim 0(20)100
	local mult 100
}
if `obsnum' == 26 {
	local var diag_learn
	local ylim 0(20)100
	local mult 100
}
if `obsnum' == 27 {
	local var diag_dd
	local ylim 0(10)70
	local mult 100
}
if `obsnum' == 38 {
	local var tos_phys_num
	if `yr' == 2019 local ylim 0(8)32
	else local ylim 0(3)12
	local mult 1
}
if `obsnum' == 39 {
	local var tos_rx_num
	local ylim 0(8)32
	local mult 1
}
local graph_combine

if inlist(`obsnum',38,39) local ylab "Number of claims"
else local ylab "Percentage"

foreach st in AR CO LA MA {

import excel "`root'/Analytic File/`yr'/tables_`yr'_`dt'.xlsx", first clear cellrange(A4) sheet("`st'_`yr'")

ren *, l

drop if variable == "_n" | obs == .
destring mean_*, replace force

// Keep only the relevant row for the characteristic of interest
keep if obs == `obsnum'
ren mean_*pct_prob_ssi mean_*

keep label mean_*
// Reshape this dataset to be long instead of wide (by probability threshold)
reshape long mean_nonssi_gt, i(label mean_ssi mean_non_ssi) j(prob_thresh)

label variable prob_thresh "Probability threshold"
label variable mean_nonssi_gt "`ylab'"

// Potentially multiply by 100 if interested in a percentage (established above)
	replace mean_ssi = mean_ssi * `mult'
	replace mean_non_ssi = mean_non_ssi * `mult'
	replace mean_nonssi_gt = mean_nonssi_gt * `mult'

local mean_ssi = mean_ssi[1]
local mean_non_ssi = mean_non_ssi[1]

local ytext_mean_ssi = `mean_ssi'-0.05
local ytext_mean_non_ssi = `mean_non_ssi'+0.05

// Create the scatter plot for the given state
tw sc mean_nonssi_gt prob_thresh, scheme(s1mono) ylabel(`ylim') yline(`mean_ssi', lpattern(solid) lcolor(black)) yline(`mean_non_ssi', lpattern(dash) lcolor(red)) title("`st'")
graph save "`root'/summary_graphs/graphs/`var'_`st'_`yr'.gph", replace

local graph_combine "`graph_combine' `"`root'/summary_graphs/graphs/`var'_`st'_`yr'"'"

}

// Combine across the four states into the single graph shown in the paper
graph combine `graph_combine', rows(2) cols(2) scheme(s1mono) iscale(0.75) xsize(9) ysize(6)
graph export "`root'/summary_graphs/`var'_`yr'.png", replace hei(1200)

}
